package com.example.XueCuApp.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.XueCuApp.Bean.JJHXiaoPiaoDaYingBean;
import com.example.XueCuApp.Customer.CheckResultem;
import com.example.XueCuApp.R;

import java.util.List;

public class TicketPrintAgainAdaprer extends RecyclerView.Adapter<TicketPrintAgainAdaprer.ViewHolder> {

    private Context context;
    private List<JJHXiaoPiaoDaYingBean> dataList;
    private PrintAgainListener printAgainListener;

    public TicketPrintAgainAdaprer(Context context, List<JJHXiaoPiaoDaYingBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_ticket_print_again, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        holder.orderNumber.setResultText(dataList.get(position).getOrderNo());
        holder.orderTime.setResultText(dataList.get(position).getCheckTime());
        holder.orderPeopleNumber.setResultText(dataList.get(position).getPassPersonSum());

        holder.printAgain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                printAgainListener.printAgain(position);
            }
        });

    }

    public interface PrintAgainListener{
        void printAgain(int pos);
    }

    public void SetPrintAgainListener(PrintAgainListener againListener){
        printAgainListener = againListener;
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final CheckResultem orderNumber;
        private final CheckResultem orderTime;
        private final CheckResultem orderPeopleNumber;
        private final Button printAgain;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            orderNumber = itemView.findViewById(R.id.again_adapter_order_number);
            orderTime = itemView.findViewById(R.id.again_adapter_order_check_time);
            orderPeopleNumber = itemView.findViewById(R.id.cr_ticket_order_people_number);
            printAgain = itemView.findViewById(R.id.cr_ticket_order_xiao_piao);
        }
    }
}
